<style>
.editbox
{
display:none
}
td
{
padding:5px;
}
.editbox
{
font-size:14px;
width:70px;
background-color:#ffffcc;
border:solid 1px #000;
padding:4px;
}
.edit_tr:hover
{
cursor:pointer;
}
</style>
<script type="text/javascript">
	function onlyNumbers(evt) 
	{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode
		if (charCode > 31 && (charCode < 48 || charCode > 57)) {
			//status = "This field accepts numbers only."
			alert("Harus di Isi Angka");
			return false
		}
		//status = ""
		return true
	
	}
	
	function changeStatus(obj,index)
	{
		var amount =0;
		var amount = parseInt(document.getElementById("txtAmount_" + index).value);
		
		if(document.getElementById('typebyr').value == 'CASH')
		{	
			var _totalbayar = 0;
			var ttlamount =  parseInt(document.getElementById('ttlamount').value);;
			if (isNaN (ttlamount))
			{
				ttlamount=0;
			}else { _totalbayar = ttlamount}
			
			if(obj.checked== true)
			{
				_totalbayar += amount;
			}else
			{
				_totalbayar = _totalbayar - amount;
			}
			
			document.getElementById('ttlamount').value = _totalbayar;
		}
		else if(document.getElementById('typebyr').value == 'GIRO')
		{
			var _totalbayar = 0;
			var ttlamountgiro =  parseInt(document.getElementById('ttlamountgiro').value);;
			if (isNaN (ttlamountgiro))
			{
				ttlamountgiro=0;
			}else { _totalbayar = ttlamountgiro}
			
			
			if(obj.checked== true)
			{
				_totalbayar += amount;
			}else
			{
				_totalbayar = _totalbayar - amount;
			}
			
			document.getElementById('ttlamountgiro').value = _totalbayar;
		}
		else if(document.getElementById('typebyr').value == 'BANK')
		{
			var _totalbayar = 0;
			var ttlamountbank =  parseInt(document.getElementById('ttlamountbank').value);;
			if (isNaN (ttlamountbank))
			{
				ttlamountbank=0;
			}else { _totalbayar = ttlamountbank}
			
			if(obj.checked== true)
			{
				_totalbayar += amount;
			}else
			{
				_totalbayar = _totalbayar - amount;
			}
			
			document.getElementById('ttlamountbank').value = _totalbayar;
		}
		
		document.getElementById("kdidfaktur_" + index).disabled = ! obj.checked;
		document.getElementById("tglfaktur_" + index).disabled = ! obj.checked;
		document.getElementById("txtProductname_" + index).disabled = ! obj.checked;
		document.getElementById("txtQuantity_" + index).disabled = ! obj.checked;
		document.getElementById("txtAmount_" + index).disabled = ! obj.checked;
		document.getElementById("nmasupplier_" + index).disabled = ! obj.checked;
		document.getElementById("kdesupplier_" + index).disabled = ! obj.checked;
	   	document.getElementById("\kdedetailid_" + index).disabled = ! obj.checked;	   
	}
		
	function setPaymentMethod(value){
		var paymentContainer = document.getElementById('payment-detail');
		paymentContainer.innerHTML = '';
		var cashView = '<table width="100%" cellpadding="3" cellspacing="0" border="1"><tr><td width="156"><strong>Jumlah Bayar</strong></td><td width="25" align="center"><strong>:</strong></td><td width="855" >Rp.<input type="text"  name="ttlamount" id="ttlamount" maxlength="20"/></td></tr><tr><td width="156" valign="top"><strong>Keterangan</strong></td><td width="25" valign="top" align="center"><strong>:</strong></td><td ><textarea  name="keterangan" id="keterangan" cols="20" rows="5"></textarea></td></tr></table>';
		var giroView = '<table width="100%" cellpadding="3" cellspacing="0" border="1"><tr ><td width="153"><strong>Nama Bank</strong></td><td width="25" align="center"><strong>:</strong></td><td width="857" ><input type="text"  name="nmbankgiro" id="nmbankgiro" size="25" maxlength="20" /></td></tr><tr><td width="153"><strong>No Giro</strong></td><td width="25" align="center"><strong>:</strong></td><td ><input type="text"  name="nogiro" id="nogiro" size="25" maxlength="20" /></td></tr><tr><td width="153"><strong>Tanggal Terbit</strong></td><td width="25" align="center"><strong>:</strong></td><td ><input type="text"  name="tglterbit" id="tglterbit" size="25" maxlength="20" /></td></tr><tr><td width="153"><strong>Tanggal Cair</strong></td><td width="25" align="center"><strong>:</strong></td><td ><input type="text"  name="tglcair" id="tglcair" size="25" maxlength="20" /></td></tr><tr><td width="153"><strong>Jumlah Bayar</strong></td><td width="25" align="center"><strong>:</strong></td><td width="857" colspan="3"><input type="text"  name="ttlamountgiro" id="ttlamountgiro" maxlength="20" onkeypress="return onlyNumbers(even);" /></td></tr><tr><td width="156" valign="top"><strong>Keterangan</strong></td><td width="25" valign="top" align="center"><strong>:</strong></td><td ><textarea  name="keterangan" id="keterangan" cols="20" rows="5"></textarea></td></tr></table>';
		var bankView = '<table width="100%" cellpadding="3" cellspacing="0" border="1"><tr><td width="155"><strong>Nama Bank</strong></td><td width="25" align="center"><strong>:</strong></td><td width="857"><?php echo $bankcombo?></td></tr><tr><td width="155"><strong>No Rekening</strong></td><td width="25" align="center"><strong>:</strong></td><td ><input type="text"  name="norek" id="norek" size="25" maxlength="20" readonly="readonly" /></td></tr><tr><td width="155"><strong>Jumlah Bayar</strong></td><td width="25" align="center"><strong>:</strong></td><td width="857" colspan="3"><input type="text"  name="ttlamountbank" id="ttlamountbank" maxlength="20"/></td></tr><tr><td width="156" valign="top"><strong>Keterangan</strong></td><td width="25" valign="top" align="center">:</td><td ><textarea  name="keterangan" id="keterangan" cols="20" rows="5"></textarea></td></tr></table>';
		
		if(value == 'CASH')
			paymentContainer.innerHTML = cashView;
		else if(value == 'GIRO')
			paymentContainer.innerHTML = giroView;
		else if(value == 'BANK')
			paymentContainer.innerHTML = bankView;
		else
			paymentContainer.innerHTML = '';
	}
	function getBankDetail(){
	var kodebank = $('#bank option:selected').val();
	if(kodebank != "0"){
		$.post(
				'<?php echo site_url('kwitansipembeliancontroller/getBankDetail')?>',
				{bankid:kodebank},
				function(result){
					var objJSON = JSON.parse(result);
					$('#norek').val(objJSON.NoRekening);
				}
		);
	}else{
		alert('Mohon pilih nama bank yang akan digunakan');
	}
}
</script>

<div id="container">
<h1><?php //echo $nama_perusahaan; ?></h1>
<h2><?php //echo $alamat_perusahaan; ?></h2>

<div id="body">
<?php
	//echo $bio;
	//echo $menu;
?>
<div class="cleaner_h10"></div>
<table align="center">
    <tr align="center">
        <td>
            <?php
                //echo $paginator;
            ?>
        </td>
    </tr>
</table>
<div class="cleaner_h10"></div>
<form method="post" name="frmSearch" action="<?php echo site_url('kwitansipembeliancontroller');?>">
    <table width="100%" cellpadding="3" cellspacing="0" border="1">
        <tr>
            <td width="75"><strong>No Faktur</strong></td>
            <td width="11" align="center">:</td>
            <td colspan="3">
            <input type="text"  name="nofaktur" id="nofaktur" maxlength="12" size="25" >
           <!-- <select name="nofaktur">
                <?php 
                    $count = count($mstrfaktur);
                    foreach($mstrfaktur as $comboInd)
                    {
                ?>
                    <option value="<?php echo $comboInd->NoFaktur?>"><?php echo $comboInd->NoFaktur;?></option>
                <?php }?>
            </select>-->&nbsp;| &nbsp;<input type="submit" name="btnview" value="Search"></td>
        </tr>
    </table>
</form>
<br/>
<div class="cleaner_h10"></div>
<form method="post" name="frmsave" action="<?php echo site_url('kwitansipembeliancontroller/simpan');?>">
	<table width="100%" cellpadding="3" cellspacing="0" border="1">
    	 <tr style="background-color:#FFF; color:#000000;" align="center">
            <td colspan="9" height="25"><strong>Transaction Pembelian</strong></td>
        </tr>
        <tr>
            <td width="129"><strong>Type Bayar</strong></td>
            <td width="19" align="center">:</td>
            <td width="711" >
                <select id="typebyr" name="typebyr" onchange="setPaymentMethod(this.value)">
                    <option value="0">Pilih</option>
                    <option value="CASH">Cash</option>
                    <option value="GIRO">Giro</option>
                    <option value="BANK">Bank</option>
                </select>
            </td>
        </tr>
    </table>
    <div id="payment-detail"></div>
    <br />
    <table border="1" cellpadding="3" cellspacing="0" width="100%" style=" border-collapse: collapse;" class="record" bordercolor="#CCCCCC">
        <tr style="background-color:#FFF; color:#000000;" align="center">
            <td colspan="9" height="25"><strong>LIST Transaction Pembelian</strong></td>
        </tr>
        <tr style="background-color:#333; color:#FFF;" align="center">
            <td width="9%">check</td>
            <td width="14%">No Faktur</td>
            <td width="15%">Tanggal Faktur</td>
            <td width="23%">Nama Supplier</td>
            <td width="17%">Nama Barang</td>
            <td width="11%">Quantity</td>
            <td width="11%">Amount</td>
        </tr>
        <tbody id="databayarbeli"><?php 
			$i = 0; 
			if(count($det_barang)>0){
			foreach($det_barang as $tdelay)
			{
				$style = "";
				if($i%2 == 0)$style="cellDefault"; else $style="cellAlternate";
	            echo "<tr class=\"".$style."\">";
	            echo "	<td><input type=\"checkbox\" name=\"chkitem[]\" id=\"chkitem[]\" value=\"".$tdelay->KodeDetailBarang."\" onclick=\"javascript:changeStatus(this,".$i.")\" /></td>";
	            echo "  <td><input id=\"kdidfaktur_".$i."\" name=\"kdidfaktur[]\" type=\"text\" class=\"flat-textbox-number\" style=\"text-align:right;\" size=\"50\" maxlength=\"50\" value=\"".$tdelay->NoFaktur."\" readonly=\"readonly\" disabled=\"disabled\"/></td>";
	            echo "  <td><input id=\"tglfaktur_".$i."\" name=\"tglfaktur[]\" type=\"text\" class=\"flat-textbox-number\" style=\"text-align:left;\" size=\"50\" maxlength=\"50\" value=\"".$tdelay->DateFaktur."\" readonly=\"readonly\" disabled=\"disabled\" /></td>";
	            echo "  <td><input id=\"nmasupplier_".$i."\" name=\"nmasupplier[]\" type=\"text\" class=\"flat-textbox-number\" style=\"text-align:left;\" size=\"30\" maxlength=\"30\" value=\"".$tdelay->SupplierName."\" readonly=\"readonly\" disabled=\"disabled\" /></td>";
	            echo "  <td><input id=\"txtProductname_".$i."\" name=\"txtProductname[]\" type=\"text\" class=\"flat-textbox-number\" style=\"text-align:left;\" size=\"50\" maxlength=\"50\" value=\"".$tdelay->Productname."\" readonly=\"readonly\" disabled=\"disabled\"/></td>";
	            echo "  <td><input id=\"txtQuantity_".$i."\" name=\"txtQuantity[]\" type=\"text\" class=\"flat-textbox-number\" style=\"text-align:center;\" value=\"".$tdelay->Quantity."\" readonly=\"readonly\" disabled=\"disabled\"/></td>";
	            echo "  <td><input id=\"txtAmount_".$i."\" name=\"txtAmount[]\" type=\"text\" class=\"flat-textbox-number\" style=\"text-align:right;\" value=\"".$tdelay->Amount."\" readonly=\"readonly\" disabled=\"disabled\"/></td>";	                
	            echo "	<input type=\"hidden\"  name=\"kdesupplier[]\" id=\"kdesupplier_".$i."\" size=\"30\" maxlength=\"25\" value=\"".$tdelay->KodeSupplier."\" disabled=\"disabled\" />";
				echo "	<input type=\"hidden\"  name=\"kdedetailid[]\" id=\"kdedetailid_".$i."\" size=\"30\" maxlength=\"25\" value=\"".$tdelay->IDdetail."\" disabled=\"disabled\" />";
	            echo "</tr>";
	            $i++;
			}
		?>
         <?php } else{
                echo "<tr>";
                echo "<td colspan='9' style='text-align:center;color:red;'>No Data To Display</td>";
                echo "</tr>";
        } ?>
    </table></tbody>
    <table border="1" cellpadding="3" cellspacing="0" width="100%" style=" border-collapse: collapse;" class="record" bordercolor="#CCCCCC">
    	<tr valign="top">
            <td colspan="9" align="center"><input type="submit" value="Save" name="btnSave" >&nbsp;<input type="button" name="btnClose" value="Back" class="btn" onclick="javascript:window.location='<?php echo site_url('menuhomecontroller'); ?>';" /></td>
        </tr>
    </table>
    <?php //echo $links; ?>
    <div id="det_barang" class="holder"></div>
</form>
<?php if(!empty($message))?>{message}
<div class="cleaner_h10"></div>
    <table align="center">
        <tr align="center">
            <td>
                <?php
                    //echo $paginator;
                ?>
            </td>
        </tr>
    </table>
</div>
